package com.bangyu.monitor.modular.system.service;

import com.bangyu.monitor.modular.system.entity.OriginalData;
import com.bangyu.monitor.modular.system.entity.Payload;
import com.bangyu.monitor.modular.system.entity.PayloadCount;
import com.bangyu.monitor.modular.system.mapper.PayloadMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Auther: zhangxue
 * @Date: 19/4/13 16:33
 * @Description:
 */
@Service
@Slf4j
public class PayloadService extends ServiceImpl<PayloadMapper,Payload> {

//    private static final ExecutorService executor = Executors.newFixedThreadPool(5);


    public void insertBatch(List<Payload> datas){
        if(CollectionUtils.isNotEmpty(datas)){
            log.info("荷载数据入库{}条",datas.size());
            this.baseMapper.batchInsert(datas);
        }
    }

    //异步批量保存
//    public void asynchInsertBatch(List<Payload> datas){
//        executor.execute(new Runnable() {
//            @Override public void run() {
//                insertBatch(datas);
//            }
//        });
//    }

    /**
     * 查询某梁 重型荷载和轻型荷载的数量
     * @param beamNo
     * @param startDate
     * @param endDate
     * @return
     */
    public List<PayloadCount> queryCountByPayloadType(String beamNo,Integer startDate,Integer endDate){
        return this.baseMapper.queryCountByPayloadType(beamNo,startDate,endDate);
    }

}
